package com.zzy.util;

import com.zzy.model.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class UtilUser {

    public static User getSessionUser(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        User user = null;
        if(request!=null){
            user = (User)request.getSession().getAttribute("user");
        }
       if(user==null){
           user = new User();
       }
        return  user;
    }
}
